<?php 
	$this->load->view("partial/header"); 
?>
<script type="text/javascript">
	$(document).ready(function()
	{
	    enable_select_all();
	    enable_checkboxes();
	    enable_row_selection();
	    enable_search('<?php echo site_url("services/suggest")?>','<?php echo lang("common_confirm_search")?>');
	});    
</script>

<table id="title_bar">
	<tr>
		<td id="title_icon">
			<img src='<?php echo base_url()?>images/menubar/sales.png' alt='title icon' />
		</td>
		<td id="title">
			<?php 
				echo lang('services_register'); 
			?>
		</td>
		<td id="title_search">
			<?php echo form_open("services/search",array('id'=>'search_form')); ?>
				<input type="text" name ='search' id='search'/>
				<img src='<?php echo base_url()?>images/spinner_small.gif' alt='spinner' id='spinner' />
			</form>
		</td>
	</tr>
</table>

<table id="contents">
	<tbody>
		<tr>
			<td id="commands">
				<div id="new_button">
					<!-- New service -->
					<?php echo anchor("services/view/-1/width~550",
					"<div class='small_button'><span>".lang('services_new_item')."</span></div>",
					array('class'=>'thickbox none new','title'=>lang('services_new_item')));
					?>
					
					<!-- Make receipt - Redirect to item page -->
					<div id="div_make_receipt" style="margin-bottom:10px;" class= "make_receipt_services_inactive make_receipt_inactive">
						<?php 
							echo form_open("services/make_receipt",array('id'=>'finish_make_receipt')); 
							echo "<input type='hidden' name='make_receipt_list' id='make_receipt_list' value='' />";
							echo "<div class='small_button' id='make_receipt'><span>Make Receipt</span></div>" ;
							echo form_close();	
						?>
					</div>
					
					<!-- Print receipt -->
					<div id="div_print" style="margin-bottom:10px;" class= "print_receipt_services_inactive">
						<?php 
							echo form_open("services/complete",array('id'=>'finish_print_receipt')); 
							echo "<input type='hidden' name='type' class='type' value='' />";
							echo "<input type='hidden' name='receipt_list' id='receipt_list' value='' />";
							echo "<div class='small_button' id='print_receipt'><span>Print Receipt</span></div>" ;
							echo form_close();	
						?>
					</div>
					<!-- Print order -->
					<div id="div_print_services" class="print_services_inactive" style="margin-bottom:10px;" >
						<?php 
							echo form_open("services/complete",array('id'=>'finish_print_form')); 
							echo "<input type='hidden' name='type' class='type' value='' />";
							echo "<input type='hidden' name='service_list' id='service_list' value='' />";
							echo "<div class='small_button' id='print_services'><span>Print Invoice</span></div>" ;
							echo form_close();	
						?>
					</div>
					<!-- Update return -->
					<div id="div_return_services" class="return_services_inactive" style="margin-bottom:10px;" >
						<?php 
							echo form_open("services/serv_return",array('id'=>'finish_return_form')); 
							echo "<input type='hidden' name='service_list' id='serv_list' value='' />";
							echo "<div class='small_button' id='return_services'><span>Return</span></div>" ;
							echo form_close();	
						?>
					</div>
					<!-- Delete services -->
					<div id="div_delete_services" class="delete_services_inactive">
						<?php 
							echo form_open("services/delete",array('id'=>'finish_delete_form')); 
							echo "<input type='hidden' name='serv_delete_list' id='serv_delete_list' value='' />";
							echo "<div class='small_button' id='delete_services'><span>Delete</span></div>" ;
							echo form_close();	
						?>
					</div>
				</div>
			</td>
			<td style="width:10px;"></td>
			<td id="item_table">
				<div id="table_holder">
					<table id="sortable_table" class="tablesorter">
						<thead>
							<tr>
								<th width='5%' class="leftmost"><input type="checkbox" id="select_all" /></th>
								<th id="reg_item_name"><?php echo "Order ID"; ?></th>
								<th id="reg_item_name"><?php echo lang('name_of_customer'); ?></th>
								<th id="reg_item_name"><?php echo lang('customer_phone'); ?></th>
								<th id="reg_item_stock"><?php echo lang('product_brand'); ?></th>
								<th id="reg_item_stock"><?php echo lang('product_model'); ?></th>
								<th id="reg_item_stock"><?php echo lang('product_cost'); ?></th>
								<th id="reg_item_name"><?php echo lang('product_date_return'); ?></th>
								<th id="reg_item_stock"><?php echo lang('product_status'); ?></th>
								<th id="reg_item_stock" class="rightmost"><?php echo lang('services_actions');?></th>
							</tr>
						</thead>
						<tbody>
							<?php
								if(count($cart)==0)
								{
							?>
									<tr>
										<td colspan='11' style="height:60px;border:none;">
											<div class='warning_message' style='padding:7px;'><?php echo lang('services_no_items'); ?></div>
										</td>
									</tr>
							<?php
								}
								else
								{
									foreach($cart as $key=>$value)
									{
									?>
										
										<tr id="reg_item_top">
											<td width='5%'><input type='checkbox' id="item_<?php echo $value['service_id'];?>" value="<?php echo $value['service_id'] ;?>"/></td>
											<td><?php echo $value['print']; ?></td>
											<td><?php echo $value['customer_name'];?></td>
											<td><?php echo $value['phone_num'];?></td>
											<td><?php echo $value['product_brand']; ?></td>
											<td><?php echo $value['product_model']; ?></td>
											<td><?php echo $value['service_cost']; ?></td>
											<td>
                                                                                            <?php
                                                                                                $date = explode('-',$value['date_return']); 
                                                                                                echo $date[2].'-'.$date[1].'-'.$date[0];
                                                                                            ?>
                                                                                        </td>
											<td><?php echo $value['status']; ?></td>
											<td>
												<?php 
												echo anchor("services/view/".$value['service_id']."/width~550",
												"<div class='small_button'><span>".lang('services_edit')."</span></div>",
												array('class'=>'thickbox none','title'=>lang('services_edit')));
												?>
											</td>
										</tr>
									<?php
									echo form_close();
									}
									
									
								}
							?>
						</tbody>
					</table>
				</div>
				<div id="pagination">
					<?php echo $this->pagination->create_links();?>
				</div>
			</td>
		</tr>
	</tbody>
</table>

<script type="text/javascript">
<?php
	if(isset($error))
	{
		echo "set_feedback('$error','error_message',false);";
	}
	
	if (isset($warning))
	{
		echo "set_feedback('$warning','warning_message',false);";
	}
	
	if (isset($success))
	{
		echo "set_feedback('$success','success_message',false);";
	}
?>
</script>

</div>

<?php $this->load->view("partial/footer"); ?>

<script type="text/javascript" language="javascript">
$(document).ready(function()
{
	$("#print_report_bt").click(function()
    {
    	$('#finish_print_form').submit();
    });

	$("#print_services").click(function(){
    	var services_selected = get_selected_values();
    	if (services_selected.length == 0)
    	{
    		alert('<?php echo "You have not selected any services to print invoice !"; ?>');
    		return false;
    	}else{
    		$res = confirm('Are you sure print services selected ?');        
			if($res==true){
		    	$(".type").val('print_invoice');
		    	$("#service_list").val(services_selected);
		    	$('#finish_print_form').submit();
			}
    	}
    });

    $("#print_receipt").click(function(){
    	var serv_selected = get_selected_values();
    	if (serv_selected.length == 0)
    	{
    		alert('<?php echo "You have not selected any services to print receipt !"; ?>');
    		return false;
    	}else{
			$res = confirm('Are you sure print receipt for services selected ?');        
			if($res==true){
				$(".type").val('print_receipt');
				$("#receipt_list").val(serv_selected);
				$('#finish_print_receipt').submit();
			}
    	}
    	
    });

    $("#return_services").click(function(){
    	var serv_selected = get_selected_values();
    	if (serv_selected.length == 0)
    	{
    		alert('<?php echo "You have not selected any services to return !"; ?>');
    		return false;
    	}else{
			$res = confirm('Are you sure return services selected ?');        
			if($res==true){
				$("#serv_list").val(serv_selected);
		    	$('#finish_return_form').submit();
			}
    	}
    	
    });

    $("#make_receipt").click(function(){
    	var serv_selected = get_selected_values();
    	if (serv_selected.length == 0)
    	{
    		alert('<?php echo "You have not selected any services to make receipt !"; ?>');
    		return false;
    	}else{
			$res = confirm('Are you sure make receipt for services selected ?');        
			if($res==true){
				$("#make_receipt_list").val(serv_selected);
				$('#finish_make_receipt').submit();
			}
    	}
    	
    });

    $("#delete_services").click(function(){
    	var serv_delete_selected = get_selected_values();
    	if (serv_delete_selected.length == 0)
    	{
    		alert('<?php echo "You have not selected any services to delete !"; ?>');
    		return false;
    	}else{
    		$res = confirm('Are you sure delete services selected ?');        
			if($res==true){
		    	$("#serv_delete_list").val(serv_delete_selected);
		    	$('#finish_delete_form').submit();
			}
    	}
    });
});
	var url = "<?php echo site_url("services");?>";
	
	function post_service_form_submit(response)
	{
		if(response.success)
		{
			location.reload();
		}
	}
</script>